@extends('Home.Common')

@section('include_css')

@endsection

@section('include_js')
    <script type="text/javascript">
        //    getClickAttr();
        // 点击 编辑 显示
        $('.permission-edit').on('show.bs.modal',function(){
            var data = {};
            data.Id = $('#example1').attr('data-id');
            data.Name = $('table tr[data-id='+data.Id+'] td[name=Name]').html();
            for(var i in data){
                $('.permission-edit form input[name='+i+']').val(data[i]);
            }
        });


        // 点击 编辑 确认
        $('.permission-edit button.btn-primary').click(function(){

            var data = {};
            data._token = $('meta[name=_token]').attr('content');
            data.id = $('.permission-edit form input[name=Id]').val();
            data.name = $('.permission-edit form input[name=Name]').val();
            var res;
            $.ajax({url:'{{ action('Home\PermissionController@edit') }}',data:data,type:'post',async:false,
                success:function(data){
                    res = data;
                },error:function(){

                }});
            if(!res || !res.status){
                alert_info('修改失败');
                return false;
            }
            for(var i in data){
                $('table tr[data-id='+data.id+'] td[name='+i+']').html(data.name);
            }
            alert_info('修改成功','',1);
            $('.permission-edit').modal('hide');
        })

    </script>
@endsection

@section('Modal')


    <div class="modal fade permission-edit"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">权限名称</h4>
                </div>
                <form action="" class="form-horizontal">
                    <div class="modal-body">
                        <div class="form-group">
                            <input class="form-control" type="hidden" name="Id" >
                            <div class="col-sm-12 text-left">
                                <input class="form-control" type="text" name="Name" >
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary">确认</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

@endsection

@section('content')

    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <h3 class="box-title">{{ session('action.Name') }}</h3>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive ">
                    <table id="example1" class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th style="min-width:120px;">编号</th>
                            <th style="min-width:120px;">权限名称</th>
                            <th style="min-width:120px;">权限链接</th>
                            <th>编辑</th>
                            {{--<th>删除</th>--}}
                        </tr>
                        </thead>

                        <tbody>
                        @foreach($data as $info)
                            <tr data-id="{{ $info->id }}">
                                <td>{{ $info->id }}</td>
                                <td name="name">{{ $info->name }}</td>
                                <td>{{ $info->action }}</td>
                                <td>
                                    <button class="btn btn-success btn-xs" data-toggle="modal" data-target=".permission-edit">编辑</button>
                                </td>
                                {{--<td>--}}
                                {{--<button class="btn btn-danger btn-xs" data-toggle="modal" data-target=".Shop-delete">编辑</button>--}}
                                {{--</td>--}}
                            </tr>
                        @endforeach
                        </tbody>
                        <tfoot>
                        <tr>
                            <th colspan="6" class="text-right" style="padding:1rem 2rem 1rem 2rem;">
                                {!! $data->links('Page') !!}
                            </th>
                        </tr>
                        </tfoot>
                    </table>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
        <!-- /.col -->
    </div>


@endsection